<template>
  <div class="dashboard-editor-container">
    <panel-group @handleSetLineChartData="statLast30" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row>

  </div>
</template>

<script>

import { ipcRenderer } from 'electron'
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import { statLast30 } from '@/api/order'

export default {
  name: 'Dashboard',
  components: {
    PanelGroup,
    LineChart
  },
  data() {
    return {
      lineChartData: {
        dateData: [],
        amountData: []
      }
    }
  },
  created: function() {
    // 1.设置chart
    this.statLast30()

    // 2绑定快捷键
    // 2.1 支付 alt+s
    ipcRenderer.on('open-pay', (event, arg) => {
      this.$router.push({ path: '/fcolloec' })
    })

    // 2.2 订单 alt+p
    ipcRenderer.on('open-order', (event, arg) => {
      this.$router.push({ path: '/order' })
    })
  },
  methods: {
    statLast30() {
      statLast30({ 'merchantCode': this.merchantCode }).then(res => {
        if (res != null && res.code === 0) {
          this.lineChartData = {
            dateData: res.data.dateData,
            amountData: res.data.amountData
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>
